package main;

import ilog.concert.IloException;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import solver.SimpleSolver;
import tools.*;
import uncertainty.*;
import problem.*;

public class MainWareHouseProblem {

	public static void main(String[] args){
		UncertaintySet Xi;
		SingleWareHouseProblem problem;
		Vector<Double> demandcost;
		Vector<Double> storagecost;
		Vector<Double> shortagevost;
		Vector<Double> demandlimits;
		int k = Integer.parseInt(args[1]);
		int dim= Integer.parseInt(args[2]);
		double solution;
		String filename = args[3];
		
		try {
			InputStream demtream = new FileInputStream(args[4]);
			InputStream shttream = new FileInputStream(args[5]);
			InputStream stgtream = new FileInputStream(args[6]);
			InputStream limtream = new FileInputStream(args[7]);
			InputStream ustream = new FileInputStream(args[8]);
			FileOutputStream file = new FileOutputStream(args[9]);
			
			DataInputStream demFile = new DataInputStream(demtream);
			DataInputStream shtFile = new DataInputStream(shttream);
			DataInputStream stgFile = new DataInputStream(stgtream);
			DataInputStream limFile = new DataInputStream(limtream);
			DataInputStream usFile = new DataInputStream(ustream);
			
			demandcost = MainFunctions.readDemandCosts(demFile);
			storagecost = MainFunctions.readStorageCosts(stgFile);
			shortagevost = MainFunctions.readShortageCosts(shtFile);
			demandlimits = MainFunctions.readBounds(limFile);
			
			Xi = MainFunctions.readUncertainSet(usFile);
			problem = new SingleWareHouseProblem(Xi, dim, k, demandcost, storagecost, shortagevost, demandlimits);
			
			SimpleSolver solver = new SimpleSolver(problem, Xi, k); 
			
			solver.build();
			
			solution = solver.solve();
			
			
			MainFunctions.writeSol(file, filename, solution);
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IloException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
